(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth || clientWidth > 768) {
                window.remBaseFontSize = '16px';
                return;
            }
            docEl.style.fontSize = 16 * (clientWidth / 640) + 'px';
            window.remBaseFontSize = docEl.style.fontSize;
        };

    if (!doc.addEventListener) {return;}
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
$(function() {
    // $('.doc-intro-section').height($(window).height());
    var animCss = new WOW({
        boxClass: 'animCss',
    });
    animCss.init();

    // 点击下载
    var userAgent = navigator.userAgent;
    var isiOS = function() {
        return (/(iPad|iPhone|iPod)/gi).test(userAgent);
    };
    var isAndroid = function() {
        return (/(Android)/gi).test(userAgent);
    };
    var link = '';
    if (isiOS()) {
        link = 'https://itunes.apple.com/cn/app/mei-zhu/id1097737012';
    } else if (isAndroid()) {
        link = 'http://android.myapp.com/myapp/detail.htm?apkName=com.uclbrt.meizhu';
    } else {
        link = 'http://qrm.uclbrt.com/product.html';
    }
    $('.app-download').on('touchend', function() {
        window.location = link;
    });
    $('.app-download').on('click', function() {
        window.location = link;
    });

    var topDownload = $('#doc-intro-1 .app-download');
    var bottomDownload = $('#doc-footer .app-download');
    var getTopBottomBound = function() {
        window.topPx = topDownload.offset().top + topDownload.height();
        window.bottomPx = bottomDownload.offset().top - window.screen.height;
    };

    var downloadObj = $('#doc-fixed-download');
    // 悬浮下载的隐藏
    $(document).bind('scroll', function() {
        var len = $(this).scrollTop();
        getTopBottomBound();
        if (len >= window.topPx && len < window.bottomPx) {
            downloadObj.removeClass('hidden');
        } else {
            downloadObj.addClass('hidden');
        }
    });
    $(document).trigger('scroll');
});
